<?php session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
if(isset($_SESSION['lang']))
    require_once "./language_files/sendEmailForm_" . $_SESSION['lang'] . ".php";
else
    require_once "./language_files/sendEmailForm_en.php";

require_once "functions.php";

if(isset($_GET['conference_id']))
{
    $c=intval($_GET['conference_id']);
    $confid=mysql_real_escape_string($c);
}
else
{
    $c=intval($_POST['confID']);
    $confid=mysql_real_escape_string($c);
}
$conference_name=get_conference_name($confid);
echo"
	</br><span class=breadcrumbs><a href='subscriberConferencePage.php?conference_id={$confid}'>" . $conference_name . "</a>" . " > " . $lang['text_1'] . "</span>";
?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <link href="style3.css" rel="stylesheet" type="text/css" />
        <?php include 'jquery.php';?>
        <script type="text/javascript" src="functions.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                check_top();
            });
        </script>
        <title><?php echo $lang['send'];?></title>
    </head>
    <body>
        <!-- Creating the Email Submission form, the user have to fill in, in order to send an Email-->
        <h2><?php echo $lang['text_1'];?></h2>
        <form action="" method="post" name="SendEmail" enctype="multipart/form-data">
            <input name="confID" type="hidden" value="<?php echo $confid?>"/>
            <p><?php echo $lang['hint'];?><br/>
            </p>
            <p><?php echo $lang['subject'];?><br/>
                <input name="subject" size="35" maxlength="100"/>
            </p>
            <p><strong><?php echo $lang['msg'];?></strong></p>
            <p>
                <textarea name="textarea" cols="75" rows="10"></textarea>
            </p>
            <p>
                <input name="SubmitButton" type="submit" value="<?php echo $lang['smail'];?>"/>
                <input name="clear" type="reset" value="Clear"/>
                <input name="confid" type="hidden"  value="<?php echo $confid;?>"/>
            </p>
        </form>
    </body>
</html>
<?php
if(isset($_POST['SubmitButton']))
{
// Staring a session and mysql connection

    $id=$_SESSION['member_id'];
    $confid=mysql_real_escape_string($_POST['confid']);

// Identifying the logged-in user and collecting some information about him
    $query=mysql_query("SELECT * FROM member WHERE member_id ='$id'");
    $row=mysql_fetch_array($query);
    $firstname=$row['first_name'];
    $lastname=$row['last_name'];
    $email=$row['email'];
    $text=mysql_real_escape_string($_POST['textarea']);
    $message=mysql_real_escape_string($_POST['textarea']);
    $subject=mysql_real_escape_string($_POST['subject']);

// Identifying the reciever's email
    $query=mysql_query("SELECT * FROM conference WHERE conference_id ='$confid'");
    $row=mysql_fetch_array($query);

    $recieverid=$row['creator_id'];

    $query=mysql_query("SELECT * FROM member WHERE member_id ='$recieverid'");
    $row=mysql_fetch_array($query);
    $to=$row['email'];
// Creating the Email Template
    $message=<<<EMAIL
Hello my name is $firstname $lastname
$text

Yours $firstname $lastname
Email : $email

EMAIL;
// Creating Error Template
    $error=<<<ERROR
Email Sending Failed, it could for one of the following reasons: <br/>
1- There was no subject. <br/>
2- The message was empty. <br/>

ERROR;

    $from=$lang['from'] . $email;

// Checking for the validity of the message
    $mail=mail($to,$subject,$message,$from);
    if(!$mail || $subject == '' || $text == '')
    {
        echo "$error";
    }
    else
    {
        echo $lang['sent'];
    }
    mysql_close();
}
?>